package com.zbkj.crmeb.merchant.admin.controller;

import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.user.model.UserTag;
import com.zbkj.crmeb.user.request.UserTagRequest;
import com.zbkj.crmeb.user.service.UserTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * 用户标签表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/mer/user/tag")
@Api(tags = "会员 -- 标签")
public class MerUserTagController  extends AdminBaseController {

    @Autowired
    UserTagService userTagService;

    @ApiOperation(value = "列表")
    @GetMapping("/list")
    public CommonResult<Object> listLabel(HttpServletRequest servletRequest) {
        return CommonResult.success(userTagService.listTag(getMerId(servletRequest)));
    }

    @ApiOperation(value = "分页列表")
    @GetMapping("/page")
    public CommonResult<Object> pageLabel(UserTagRequest request, HttpServletRequest servletRequest) {
        request.setMerId(getMerId(servletRequest));
        return CommonResult.success(userTagService.pageTag(request));
    }

    @ApiOperation(value = "新增标签")
    @PostMapping("/save")
    public CommonResult<Object> saveLabel(@RequestBody UserTag request, HttpServletRequest servletRequest) {
        request.setMerId(getMerId(servletRequest));
        return userTagService.saveTag(request) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "修改标签")
    @PutMapping("/update")
    public CommonResult<Object> updateLabel(@RequestBody UserTag request, HttpServletRequest servletRequest) {
        request.setMerId(getMerId(servletRequest));
        return userTagService.updateTag(request) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "根据id删除标签")
    @DeleteMapping("/{id}")
    public CommonResult<Object> deleteLabel(@ApiParam(value = "主键id", required = true) @PathVariable("id") Integer id, HttpServletRequest servletRequest) {
        return userTagService.deleteTag(id,getMerId(servletRequest)) ? CommonResult.success() : CommonResult.failed();
    }

}



